/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.bugeden.netdisk.vfs;

import java.io.Serializable;

/**
 * @author bug-eden
 */
public class Partition implements Serializable {

    public final static String PartitionMailSign = "PartFileMail";

    //the name of the partition
    private String name;

    /**
     * partition size
     */
    private long size = 0;

    /**
     * partition's offset in the file
     */
    private long offset = 0;

    /**
     * //todo the field is not good here
     * flag to mark partition's task has finished or not
     */
    private transient boolean hasFinished = false;

    public Partition() {
        this.name = new String("newPartition");
    }

    ;

    public Partition(String name) {
        long randId;
        java.util.Random rand = new java.util.Random();
        randId = rand.nextLong();
        StringBuffer strb = new StringBuffer();
        strb.append(PartitionMailSign).append(":").append(String.valueOf(randId))
                .append(":").append(name);
        this.name = strb.toString();
    }

    /**
     * @param psize
     */
    public void setSize(long psize) {
        size = psize;
    }

    /**
     * @param poffset
     */
    public void setOffset(long poffset) {
        offset = poffset;
    }

    /**
     * @param fin
     */
    public void setHasFinished(boolean fin) {
        hasFinished = fin;
    }

    /**
     * @return long
     */
    public long getSize() {
        return size;
    }

    /**
     * @return long
     */
    public long getOffset() {
        return offset;
    }

    /**
     * @return boolean
     */
    public boolean getHasFinished() {
        return hasFinished;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    public int getDataLength() {
        int length = 17;
        if (this.name != null)
            length += this.name.length();
        return length;
    }
}
